package com.ymt.bpm.web.rest.mobile;

import com.alibaba.fastjson.JSONObject;
import com.ymt.bpm.service.mobile.MOrgService;
import com.ymt.bpm.util.Const;
import com.ymt.bpm.util.EncodeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/mapi/v1/org")
public class MOrgResource {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private MOrgService mos;

    @GetMapping("/user/query")
    public JSONObject queryUser(HttpServletRequest req,
                                @RequestParam(value="lang", defaultValue=Const.LANG_ZH)String lang,
                                @RequestParam(value="order", defaultValue="USER_NUMBER")String order,
                                @RequestParam(value="sort", defaultValue="ASC")String sort,
                                @RequestParam("offset")int offset,
                                @RequestParam("limit")int limit,
                                @RequestParam("timezoneOffset")int timezoneOffset,
                                @RequestParam(value="search", required = false)String search) {
        if (log.isDebugEnabled()) {
            log.debug("queryUser search=" + search);
        }
        search = EncodeUtil.decode(search);
        String tenantId = (String)req.getAttribute(Const.TENANT_ID);
        return mos.queryUser(tenantId, lang, order, sort, offset, limit, timezoneOffset, search);
    }

}
